<?php
/* -------------------------------------------------------------------------------------
* 	ID:						$Id: wish_list.php 218 2013-09-22 08:01:16Z phone.mueller@googlemail.com $
* 	Letzter Stand:			$Revision: 218 $
* 	zuletzt geaendert von:	$Author: siekiera $
* 	Datum:					$Date: 2013-09-22 08:01:16 +0000 (Sun, 22 Sep 2013) $
*
* 	SEO:mercari by Siekiera Media
* 	http://www.seo-mercari.de
*
* 	Copyright (c) since 2011 SEO:mercari
* --------------------------------------------------------------------------------------
* 	based on:
* 	(c) 2000-2001 The Exchange Project  (earlier name of osCommerce)
* 	(c) 2002-2003 osCommerce - www.oscommerce.com
* 	(c) 2003     nextcommerce - www.nextcommerce.org
* 	(c) 2005     xt:Commerce - www.xt-commerce.com
*
* 	Released under the GNU General Public License
* ----------------------------------------------------------------------------------- */

require('includes/application_top.php');
$cart_empty = false;

if($_GET['wl_delete'] !='' && $_SESSION['wish_list']->in_cart($_GET['wl_delete'])) {
	$_SESSION['wish_list']->remove($_GET['wl_delete']);
	redirect(href_link(FILENAME_WISH_LIST));
}
if (isset($_GET['wl_plus']) && $_SESSION['wish_list']->in_cart($_GET['wl_plus'])) {
	$_SESSION['wish_list']->update_quantity($_GET['wl_plus'],$_SESSION['wish_list']->get_quantity($_GET['wl_plus']) + 1);
	redirect(href_link(FILENAME_WISH_LIST));
}
if (isset($_GET['wl_minus']) && $_SESSION['wish_list']->in_cart($_GET['wl_minus'])) {
	$_SESSION['wish_list']->update_quantity($_GET['wl_minus'],$_SESSION['wish_list']->get_quantity($_GET['wl_minus']) - 1);
	redirect(href_link(FILENAME_WISH_LIST));
}
if($_GET['wl_all_to_cart'] !='' && $_GET['wl_all_to_cart'] == '1') {
	$_SESSION['wish_list']->all_to_cart();
	redirect(href_link(FILENAME_SHOPPING_CART));
}

$smarty = new Smarty();
require(DIR_FS_CATALOG.'templates/'.CURRENT_TEMPLATE.'/source/boxes.php');

$breadcrumb->add(NAVBAR_TITLE_SHOPPING_CART, href_link(FILENAME_SHOPPING_CART));

require(DIR_WS_INCLUDES.'header.php');

if ($_SESSION['wish_list']->count_contents() > 0) {

	$smarty->assign('FORM_ACTION', draw_form('cart_quantity', href_link(FILENAME_WISH_LIST, 'action=update_product'), 'POST', 'name="cart_quantity"'));
	$smarty->assign('FORM_END', draw_hidden_field('submit_target','cart')."\n".'</form>');
	$hidden_options='';
	$_SESSION['any_out_of_stock'] = 0;

	$products = $_SESSION['wish_list']->get_products();

	for ($i=0, $n=sizeof($products); $i<$n; $i++) {
		if (isset($products[$i]['attributes'])) {
			while (list($option, $value) = each($products[$i]['attributes'])) {
				$hidden_options.= draw_hidden_field('id['.$products[$i]['id'].']['.$option.']', $value);
				$attributes_values = $db->db_query("SELECT
														popt.products_options_name,
														poval.products_options_values_name,
														pa.options_values_price,
														pa.price_prefix,
														pa.attributes_stock,
														pa.products_attributes_id,
														pa.attributes_model
													FROM
														".TABLE_PRODUCTS_OPTIONS." popt,
														".TABLE_PRODUCTS_OPTIONS_VALUES." poval,
														".TABLE_PRODUCTS_ATTRIBUTES." pa
													WHERE
														pa.products_id = '".$products[$i]['id']."'
													AND
														pa.options_id = '".$option."'
													AND
														pa.options_id = popt.products_options_id
													AND
														pa.options_values_id = '".$value."'
													AND
														pa.options_values_id = poval.products_options_values_id
													AND
														popt.language_id = '".(int)$_SESSION['languages_id']."'
													AND
														poval.language_id = '".(int)$_SESSION['languages_id']."'");

				$products[$i][$option]['products_options_name'] = $attributes_values->fields['products_options_name'];
				$products[$i][$option]['options_values_id'] = $value;
				$products[$i][$option]['products_options_values_name'] = $attributes_values->fields['products_options_values_name'];
				$products[$i][$option]['options_values_price'] = $attributes_values->fields['options_values_price'];
				$products[$i][$option]['price_prefix'] = $attributes_values->fields['price_prefix'];
				$products[$i][$option]['weight_prefix'] = $attributes_values->fields['weight_prefix'];
				$products[$i][$option]['options_values_weight'] = $attributes_values->fields['options_values_weight'];
				$products[$i][$option]['attributes_stock'] = $attributes_values->fields['attributes_stock'];
				$products[$i][$option]['products_attributes_id'] = $attributes_values->fields['products_attributes_id'];
				$products[$i][$option]['products_attributes_model'] = $attributes_values->fields['products_attributes_model'];
			}
		}
	}

	$smarty->assign('HIDDEN_OPTIONS',$hidden_options);
	require(DIR_WS_MODULES.'order_details_wish_list.php');

	if (STOCK_CHECK == 'true') {
	    if ($_SESSION['any_out_of_stock']== 1) {
	      if (STOCK_ALLOW_CHECKOUT == 'true') {
	        $_SESSION['allow_checkout'] = 'true';
	        $smarty->assign('info_message',OUT_OF_STOCK_CAN_CHECKOUT);

	      } else {
	        $_SESSION['allow_checkout'] = 'false';
	        $smarty->assign('info_message',OUT_OF_STOCK_CANT_CHECKOUT);
	      }

	    } else
	      $_SESSION['allow_checkout'] = 'true';
	}

	if(SHOW_SHIPPING == 'true')
		$smarty->assign('SHIPPING_INFO', $main->getShippingLink());

	if ($_GET['info_message'])
		$smarty->assign('info_message',str_replace('+',' ',$_GET['info_message']));
	$smarty->assign('BUTTON_RELOAD','<a onclick="javascript:submit_to_wish_list();" href="javascript:void(0);">'.image_button('button_update_cart.gif', IMAGE_BUTTON_UPDATE).'</a>');
 	$smarty->assign('BUTTON_BACK', '<a href="javascript:history.back();">'.image_button('button_back.gif', IMAGE_BUTTON_BACK).'</a>');
	$smarty->assign('BUTTON_CHECKOUT','<a href="'.href_link(FILENAME_WISH_LIST, 'wl_all_to_cart=1', 'SSL').'">'.image_button('button_checkout.gif', IMAGE_BUTTON_CHECKOUT).'</a>');

} else {
	$cart_empty=true;
	if ($_GET['info_message']) $smarty->assign('info_message',str_replace('+',' ',$_GET['info_message']));
	$smarty->assign('cart_empty',$cart_empty);
	$smarty->assign('BUTTON_CONTINUE','<a href="'.href_link(FILENAME_DEFAULT).'">'. image_button('button_continue.gif', IMAGE_BUTTON_CONTINUE).'</a>');
}

$smarty->assign('language', $_SESSION['language']);
$smarty->caching = false;
$main_content=$smarty->fetch(CURRENT_TEMPLATE.'/module/wish_list.html');
$smarty->assign('main_content',$main_content);

$smarty->assign('language', $_SESSION['language']);
$smarty->caching = false;
$smarty->loadFilter('output', 'note');
$smarty->loadFilter('output','trimwhitespace');
$smarty->display(CURRENT_TEMPLATE.'/index.html');
include('includes/application_bottom.php');
?>